var Redis = require("ioredis");
var redis = new Redis(
  {
    port: 6379, // Redis port
    // host: "liumingtai.com", // Redis host
    host: "127.0.0.1", // Redis host
    family: 4, // 4 (IPv4) or 6 (IPv6)
    password: "12Liumingtai",
    db: 0
  });

export default {
  async set (key, value, options = { time: 5 }) {
    var result = await redis.set(key, value);
    await redis.expire(key, options.time)
    return result
  },
  async get (key, value) {
    var result = await redis.get(key)
    try {
      return JSON.parse(result);
    } catch (e) {
      console.log('不是 json数据,=====>',e);
      return redis.get(key)
    }
  }
}